<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>异步案例分析</h2>
</body>
<script>
    //async1函数
    async function async1() {
        console.log('1'); //2
        await async2();
        console.log('2'); //6
    }

    //async2函数
    async function async2() {
        console.log('3'); //3
    }

    //同步
    console.log('4'); //1

    //定时器
    setTimeout(function() {
        console.log('5'); //8
    }, 0)

    //调用async1函数，同步
    async1();

    //promise实例化 new 同步
    new Promise(function(resolve) {
        console.log('6'); //4
        resolve();
    }).then(function() {
        console.log('7'); //7
    });

    //同步
    console.log('8'); //5
</script>

</html>